﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.DataClasses;
using System.Reflection;
using EFEntities;

namespace BLL
{
    internal static class ContextHelper
    {
        public static void TryLoadIfNotLoaded<T>(this EntityCollection<T> navigationPropertyToLoad) 
            where T : class, System.Data.Objects.DataClasses.IEntityWithRelationships
        {
            if (!navigationPropertyToLoad.IsLoaded)
                navigationPropertyToLoad.Load();
        }

        public static void TryLoadIfNotLoaded<T>(this EntityReference<T> navigationPropertyToLoad) where T :  class, System.Data.Objects.DataClasses.IEntityWithRelationships
        {
            if (navigationPropertyToLoad.EntityKey == null)
                return;
            if (!navigationPropertyToLoad.IsLoaded)
                navigationPropertyToLoad.Load();
        }
    }
}
